#include <QPainter>
#include <QPen>

#include "buttonNext.h"

buttonNext::buttonNext(QWidget *parent) : QWidget(parent)
{
    this->setFixedSize(50, 50);
    this->setCursor(Qt::PointingHandCursor);
    isMouseIn = 0;
    this->direction = Next;

}


void buttonNext::paintEvent(QPaintEvent *event)
{
    (void) event;

    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);

    painter.fillRect(this->rect(), QColor(0, 0, 0, 0));

    QPen pen;
    pen.setWidth(1);
    pen.setCapStyle(Qt::RoundCap);

    if(isMouseIn == 1)
    {
        pen.setColor(QColor(0xFF, 0xFF, 0xFF, 0xFF));
    }
    else
    {
        pen.setColor(QColor(0xEE, 0xEE, 0xEE, 0xEE));
    }
    painter.setPen(pen);

    painter.drawEllipse(8, 8, 34, 34);

    pen.setWidth(3);
    pen.setColor(QColor(0xEE, 0xEE, 0xEE, 0xEE));
    painter.setPen(pen);

    QBrush brush;
    brush.setColor(QColor(0xEE, 0xEE, 0xEE, 0xEE));
    brush.setStyle(Qt::SolidPattern);
    painter.setBrush(brush);

    if(direction == Next)
    {
        painter.drawLine(QPointF(32, 17), QPointF(32, 33));
        QPointF points[3] = {QPointF(18, 17),
                             QPointF(18, 33),
                             QPointF(32, 25)};
        painter.drawPolygon(points, 3);
    }
    else
    {
        painter.drawLine(QPointF(18, 17), QPointF(18, 33));
        QPointF points[3] = {QPointF(32, 17),
                             QPointF(32, 33),
                             QPointF(18, 25)};
        painter.drawPolygon(points, 3);
    }

}



void buttonNext::enterEvent(QEvent *event)
{
    (void) event;

    this->isMouseIn = 1;
    this->update();
}

void buttonNext::leaveEvent(QEvent *event)
{
    (void) event;
    this->isMouseIn = 0;
    this->update();
}


int buttonNext::setDire(enum buttonDire d)
{
    this->direction = d;
    return 1;
}

void buttonNext::mousePressEvent(QMouseEvent *event)
{
    if(direction == Next)
    {
        emit getNext(NEXT);
    }
    else
    {
        emit getNext(PRE);
    }
}
